import complex_query from '@dfeidao/atom-nodejs/db/complex-query';
import { IncomingHttpHeaders } from 'http';
import { systemid } from '../../atom/config';

interface Message {
	staff_no: string;
	conference_theme: string;
	start_time: number;
	start_time1: number;
	pn: number;
}
export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders) {
	const query = complex_query(action_id, session_id, systemid);


		if (!message.start_time && !message.start_time1) {
				// 添加字段
				 const res = await query
				.add_field('meeting_administration', 'meeting_no', 'meeting_no')
				.add_field('meeting_administration', 'meeting_name', 'meeting_name')
				.add_field('meeting_administration', 'start_time', 'start_time')
				.add_field('meeting_administration', 'conference_theme', 'conference_theme')
				.add_field('meeting_administration', 'meeting_status', 'meeting_status')
				.add_field('meeting_administration', 'sponsor', 'sponsor')
				.add_field('meeting_administration', 'meeting_address', 'meeting_address')
				.where_like('meeting_administration', 'conference_theme', '%' + message.conference_theme + '%')
				// 大于
				// .where_gt('meeting_administration', 'start_time', message.start_time)
				 // 小于
				// .where_lt('meeting_administration', 'start_time', message.start_time1)
				.where_eq('meeting_administration','sponso_no',message.staff_no)
				.page(20,message.pn)
				.exec();
				const s = await query
				// 添加字段
				.add_field('meeting_administration', 'meeting_no', 'meeting_no')
				.add_field('meeting_administration', 'meeting_name', 'meeting_name')
				.add_field('meeting_administration', 'start_time', 'start_time')
				.add_field('meeting_administration', 'conference_theme', 'conference_theme')
				.add_field('meeting_administration', 'meeting_status', 'meeting_status')
				.add_field('meeting_administration', 'sponsor', 'sponsor')
				.add_field('meeting_administration', 'meeting_address', 'meeting_address')
				.where_like('meeting_administration', 'conference_theme', '%' + message.conference_theme + '%')
				// 大于
				// .where_gt('meeting_administration', 'start_time', message.start_time)
				 // 小于
				// .where_lt('meeting_administration', 'start_time', message.start_time1)
				.where_eq('meeting_administration','sponso_no',message.staff_no)
				.exec();
				return	{res,s};
		} else {
			const res = await query
			.add_field('meeting_administration', 'meeting_no', 'meeting_no')
			.add_field('meeting_administration', 'meeting_name', 'meeting_name')
			.add_field('meeting_administration', 'start_time', 'start_time')
			.add_field('meeting_administration', 'conference_theme', 'conference_theme')
			.add_field('meeting_administration', 'meeting_status', 'meeting_status')
			.add_field('meeting_administration', 'sponsor', 'sponsor')
			.add_field('meeting_administration', 'meeting_address', 'meeting_address')
			.where_like('meeting_administration', 'conference_theme', '%' + message.conference_theme + '%')
			// 大于
			.where_gt('meeting_administration', 'start_time', message.start_time)
			//  小于
			.where_lt('meeting_administration', 'start_time', message.start_time1)
			.where_eq('meeting_administration','sponso_no',message.staff_no)
			.page(20,message.pn)
			.exec();
			const s = await query
			// 添加字段
			.add_field('meeting_administration', 'meeting_no', 'meeting_no')
			.add_field('meeting_administration', 'meeting_name', 'meeting_name')
			.add_field('meeting_administration', 'start_time', 'start_time')
			.add_field('meeting_administration', 'conference_theme', 'conference_theme')
			.add_field('meeting_administration', 'meeting_status', 'meeting_status')
			.add_field('meeting_administration', 'sponsor', 'sponsor')
			.add_field('meeting_administration', 'meeting_address', 'meeting_address')
			.where_like('meeting_administration', 'conference_theme', '%' + message.conference_theme + '%')
			// 大于
			.where_gt('meeting_administration', 'start_time', message.start_time)
			//  小于
			.where_lt('meeting_administration', 'start_time', message.start_time1)
			.where_eq('meeting_administration','sponso_no',message.staff_no)
			.exec();
			return	{res,s};
		}



}
